import urllib.request
from lxml import etree
def resquest_get(resquest1):
    if resquest1 == 1:
        url_get = "https://sc.chinaz.com/tupian/gudianmeinvtupian.html"
        # //section[@id="selection"]/dl/dd/a
    else:
        url_get = "https://sc.chinaz.com/tupian/gudianmeinvtupian_"+str(resquest1)+".html"
    headers={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50"
    }
    resquest2=urllib.request.Request(url=url_get,headers=headers)
    return resquest2
def get_code(response2):
    resquest3=urllib.request.urlopen(response2)
    content=resquest3.read().decode("utf-8")
    return content
def down_load(down):
    tree=etree.HTML(down)
    down_date=tree.xpath("//div[@id='container']//a/img/@alt")
    down_img=tree.xpath("//div[@id='container']//a/img/@src2")
    for load in range(len(down_date)):
        date=down_date[load]
        img=down_img[load]
        urlimg="https:"+img
        urllib.request.urlretrieve(url=urlimg,filename="./load1/"+date+".jpg")
if __name__ == '__main__':
    page1 = int(input("起始页面"))
    page2 = int(input("结束页面"))
    for page in range(page1, page2 + 1):
        resquest = resquest_get(page)
        response=get_code(resquest)
        down_load(response)